using System.Collections.Generic;
using Amazon.ECS;
using System;
using Amazon.ECS.Query;
using Castle.Core;
namespace RomanJendrusz.Amazon.ETL.Infrastructure.Bus
{
    public class AmazonECSFactory
    {
        static readonly List<string> awsKeys = new List<string>();
        private readonly object _sync = new object();

        public void AddAwsUserKey(string key)
        {
            lock (_sync)
            {
                awsKeys.Add(key);
            }
        }

        public AmazonECS GetAmazonECS()
        {
            var random = new Random();
            lock(_sync)
            {
                if(awsKeys.Count == 0)
                {
                    throw new InvalidOperationException("Can't create the amazon ecs because no access key was specifid");
                }
                var next = random.Next(awsKeys.Count);
                return new AmazonECSQuery(awsKeys[next]);
            }
        }
    }
}